package com.wt.springsamples.es;

import co.elastic.clients.elasticsearch.ElasticsearchClient;
import co.elastic.clients.elasticsearch.indices.GetIndexResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.elasticsearch.client.Request;
import org.elasticsearch.client.Response;
import org.elasticsearch.client.RestClient;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
import org.springframework.data.elasticsearch.core.index.Settings;
import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates;

@SpringBootApplication
public class EsSamplesApplication {
    private static final Log logger = LogFactory.getLog(EsSamplesApplication.class);
    public static void main(String[] args) {

        ApplicationContext applicationContext = SpringApplication.run(EsSamplesApplication.class, args);

        RestClient restClient = applicationContext.getBean(RestClient.class);
        ;

        ElasticsearchRestTemplate template = applicationContext.getBean(ElasticsearchRestTemplate.class);

        try {

            Request request = new Request("GET","/");
            Response response = restClient.performRequest(request);
            logger.info("============getIndexResponse===》》》 " + response.getEntity().getContent());
            Settings settings = template.indexOps(IndexCoordinates.of("products")).getSettings();
            logger.info("===============》》》 " + settings);
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
